package client;

import java.io.FileInputStream;
import java.io.IOException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.util.Properties;

import transaction.InvalidTransactionException;
import transaction.TransactionAbortedException;
import transaction.WorkflowController;

public class Client1 {
	public static void main(String [] args) throws IOException, NotBoundException {
		Properties prop = new Properties();
		prop.load(new FileInputStream("conf/ddb.conf"));

		WorkflowController wc = (WorkflowController) Naming.lookup(WorkflowController.RMIName);
		int xid = -1;
		try {
			xid = wc.start();
			wc.addFlight(xid, "NO1", 100, 700);
//			wc.addCars(xid, "Shanghai", 100, 1000);
//			wc.addRooms(xid, "Shanghai", 100, 500);
//			wc.newCustomer(xid, "ding");
//			wc.deleteCustomer(xid, "ding");
//			wc.reserveCar(xid, "ding", "Shanghai");
//			wc.reserveFlight(xid, "ding", "NO1");

			wc.commit(xid);
		} catch (TransactionAbortedException | InvalidTransactionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		int numAvail = -1;
		try{
			xid = wc.start();
			numAvail = wc.queryFlight(xid, "NO1");
//			numAvail = wc.queryRooms(xid, "Shanghai");
//			numAvail = wc.queryRooms(xid, "Shanghai");
//			numAvail = wc.queryCarsPrice(xid, "Shanghai");
//			numAvail = wc.queryRoomsPrice(xid, "Shanghai");
//			numAvail = wc.queryFlightPrice(xid, "NO1");
//			numAvail = wc.queryCustomerBill(xid, "ding");

			wc.commit(xid);
		}catch(Exception e){
			e.printStackTrace();
		}
		System.out.println("num avail of Shanghai is :"+numAvail);
	}

}
